﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reviewer.Data.Bases;
using Reviewer.Entities;
using MySql.Data.MySqlClient;
using Reviewer.Utilities.Data;

namespace Reviewer.Data
{
    [CLSCompliant(false)]
    public class GameTopImageRepository : RepositoryCrudBase<GameTopImage, Guid>
    {
        #region fields
        private const string TABLE_NAME = "V2_SpilTopBilled";
        private static readonly CrudColumnInfo columnGameId = new CrudColumnInfo(0, "SpilID", MySqlDbType.VarChar, 36, true, false, false, false);
        private static readonly CrudColumnInfo columnFilename = new CrudColumnInfo(1, "Filnavn", MySqlDbType.VarChar, 255, false, false, true);
        private static readonly CrudColumnInfo columnLogoText = new CrudColumnInfo(2, "TextInLogo", MySqlDbType.VarChar, 5, false, false, true);
        private static readonly CrudColumnInfo columnLogoTextColor = new CrudColumnInfo(3, "TextColor", MySqlDbType.VarChar, 8, false, false, true);
        #endregion

        #region methods (protected)
        internal override CrudColumnInfo[] Columns
        {
            get
            {
                return new CrudColumnInfo[]{
                    GameTopImageRepository.columnGameId
                    ,GameTopImageRepository.columnFilename
                    ,GameTopImageRepository.columnLogoText
                    ,GameTopImageRepository.columnLogoTextColor};
            }
        }

        protected override string TableName
        {
            get { return GameTopImageRepository.TABLE_NAME; }
        }

        internal override object ColumnToValue(CrudColumnInfo info, GameTopImage item)
        {
            if (info.Equals(GameTopImageRepository.columnGameId)) return item.GameId;
            else if (info.Equals(GameTopImageRepository.columnFilename)) return item.FileName;
            else if (info.Equals(GameTopImageRepository.columnLogoText)) return item.LogoInText ? Boolean.TrueString : Boolean.FalseString;
            else if (info.Equals(GameTopImageRepository.columnLogoTextColor)) return item.LogoTextColor;
            return null;
        }

        protected override GameTopImage BuildItemFromReader(System.Data.IDataReader reader)
        {
            GameTopImage item = new GameTopImage();
            if (reader != null)
            {
                item.GameId = DataReaderUtility.GetValue(reader, reader.GetOrdinal(GameTopImageRepository.columnGameId.Name), Guid.Empty);
                item.FileName = DataReaderUtility.GetValue(reader, reader.GetOrdinal(GameTopImageRepository.columnFilename.Name), String.Empty);
                item.LogoInText = Boolean.Parse(DataReaderUtility.GetValue(reader, reader.GetOrdinal(GameTopImageRepository.columnLogoText.Name), Boolean.FalseString));
                item.LogoTextColor = DataReaderUtility.GetValue(reader, reader.GetOrdinal(GameTopImageRepository.columnLogoTextColor.Name), String.Empty);
            }
            return item;
        }
        #endregion
    }
}
